/**
 * 
 */
package com.miolr.module.core.api;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;

import java.util.List;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.miolr.module.core.config.HibernateDevConfig;
import com.miolr.module.core.config.SocialConfig;
import com.miolr.module.core.model.User;
import com.miolr.module.core.service.UserService;

/**
 * @author iday
 * 
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { HibernateDevConfig.class, SocialConfig.class })
@ActiveProfiles("dev")
public class UserResourceTestCase {
	@Autowired
	UserResource api;
	@Autowired
	UserService service;
	User user;

	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
		user = new User();
		user.setUsername("Ya-h0o_ya.hoo.com");
		user.setEmail("yahoo@yahoo.com");
		user.setPassword("test");
		service.save(user);
	}

	/**
	 * @throws java.lang.Exception
	 */
	@After
	public void tearDown() throws Exception {
		service.delete(user);
		user = null;
	}

	/**
	 * Test method for {@link com.miolr.module.core.api.UserResource#getUser()}.
	 */
	@Test
	public void testGetUser() {
		User u = api.getUser(user.getId());
		assertNotNull(u.getCreated());
		assertNotNull(u.getLastModified());
		api.update(user);
		assertNotSame(user.getLastModified(), u.getLastModified());
	}

	@Test
	public void testGetUsers() throws Exception {
		List<User> list = api.getUsers(1, 20);
		assertEquals(1, list.size());
	}

}
